#ifndef __SM4_H__
#define __SM4_H__
#include <typescommon.h>
// #include <stdint.h>
// typedef char int8_t;
// typedef unsigned char uint8_t;
// typedef int int16_t;
// typedef unsigned int uint16_t;
// typedef long int32_t;
// typedef unsigned long uint32_t;



#ifdef __cplusplus
extern "C"
{
#endif

#if !defined(inline) && !defined(__cplusplus)
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define sm4_inline inline
#elif defined(__GNUC__) && __GNUC__ >= 2
#define sm4_inline __inline__
#elif defined(_MSC_VER)
#define sm4_inline __inline
#else
#define sm4_inline
#endif
#else
#define sm4_inline inline
#endif

#ifdef __cplusplus
}
#endif

#define SM4_ENCRYPT 1
#define SM4_DECRYPT 0

#define SM4_BLOCK_SIZE   16
#define SM4_KEY_SCHEDULE 32

typedef struct SM4_KEY_st
{
   uint32_t rk[SM4_KEY_SCHEDULE];
} SM4_KEY;

int SM4_set_key(const uint8_t *key, SM4_KEY *ks);

void SM4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks);
void SM4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks);

int sm4EncrypteMulti(const uint8_t *in, uint8_t *out, uint8_t cryptesize, const uint8_t *key);
int sm4DecrypteMulti(const uint8_t *in, uint8_t *out, uint8_t cryptesize, const uint8_t *key);

#define sm4EncryptePro1(encStr, encSize, encKey) sm4EncrypteMulti(encStr, encStr, encSize, encKey)
#define sm4DecryptePro1(decStr, decSize, decKey) sm4DecrypteMulti(decStr, decStr, decSize, decKey)
#endif
